﻿using Decoration.IRepository;
using Decoration.IService;
using Decoration.Models.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Decoration.Service
{
    public class RoleMenuService:BaseService<Base_RoleMenu>,IRoleMenuService
    {
        IRoleMenuRepository red;
        IBaseQueryRepository svc;
        public RoleMenuService(IRoleMenuRepository red,IBaseQueryRepository svc):base(red,svc)
        {

            this.red = red;
        }
        public bool Delete(List<Base_RoleMenu> list, bool isSave = true)
        {
            foreach (Base_RoleMenu item in list) {
                red.Delete(item);
            }
            if (isSave)
            {
                return SaveChanges();
            }
            else
            {
                return false;
            }
        }
        public bool Add(List<Base_RoleMenu> list)
        {
            ///先查询
            var menus = red.Query(o => o.RoleId == list.FirstOrDefault().RoleId).ToList();

            //再删除，不提交事务
            foreach (var menu in menus) {
                red.Delete(menu);
            }

            //最后添加，提交事务
            foreach (var menu in list) {
                red.Add(menu);
            }
            return SaveChanges();
        }
    }
}


